package com.moons.demo.aicamera.facerecognition.util.ThreadPool;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by WilsonZhang on 2018/6/14.
 */

public class ThreadPoolManager {
    private int NUMBER_OF_CORES =Runtime.getRuntime().availableProcessors() * 2 + 1;

    private int KEEP_ALIVE_TIME = 1;

    private TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.HOURS;

    private BlockingDeque<Runnable> taskQueue = new LinkedBlockingDeque<>();
    private ExecutorService mExecutorService = new ThreadPoolExecutor(NUMBER_OF_CORES, NUMBER_OF_CORES * 2
            , KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, taskQueue, new BackgroundThreadFactory(), new DefaultRejectdExecutionHandler());


    private ThreadPoolManager() {
    }

    public static ThreadPoolManager getInstance() {
        return ThreadPoolManagerHolder.sInstance;
    }

    private static class ThreadPoolManagerHolder {
        private static final ThreadPoolManager sInstance = new ThreadPoolManager();
    }


    public ExecutorService getBackgroundExecutorService() {


        return mExecutorService;
    }


}
